﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Player.Admin
{
    public partial class orders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //刷新表
                rpt_ordersSX();
                //修改信息框展示
                if (Request.QueryString["upid"] != null)
                {
                    this.pl_deleupda.Visible = false;
                    this.Pl_update.Visible = true;
                    int orid = Convert.ToInt32(Request.QueryString["upid"]);
                    List<Orders> ls = BLL.OrdersManage.SeleIdOrders(orid);
                    this.lbl_pl2orid.Text = ls[0].Or_Id.ToString();
                    this.txt_pl2usid.Text = ls[0].Or_UsId.ToString();
                    this.txt_pl2gmid.Text = ls[0].Or_GmId.ToString();
                    this.txt_pl2price.Text = ls[0].Or_Price.ToString();
                    this.txt_pl2goid.Text = ls[0].Or_Goid.ToString();
                    this.txt_pl2date.Text = ls[0].Or_Date.ToShortDateString();
                }
                //删除提示
                if (Request.QueryString["deid"] != null)
                {
                    this.pl_delete.Visible = true;
                }
            }
            
        }

        //刷新
        private void rpt_ordersSX()
        {
            this.rptorders.DataSource = BLL.OrdersManage.SeleAllOrders();
            this.rptorders.DataBind();
        }

        //添加信息框显示
        protected void btn_add_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
            this.pl_deleupda.Visible = true;
            this.lbl_pltitle.Text = "添加信息";
        }

        //添加信息框隐藏
        protected void btn_plgb_Click(object sender, EventArgs e)
        {
            this.pl_deleupda.Visible = false;
        }

        //保存添加信息
        protected void txt_plctrls_Click(object sender, EventArgs e)
        {
            //获取添加内容存入Orders中
            Orders or = new Orders();
            or.Or_UsId = Convert.ToInt32(this.txt_plid.Text.Trim());
            or.Or_GmId = Convert.ToInt32(this.txt_plgmid.Text.Trim());
            or.Or_Price = Convert.ToDouble(this.txt_plprice.Text.Trim());
            or.Or_Goid = Convert.ToInt32(this.txt_plgoid.Text.Trim());
            or.Or_Date = Convert.ToDateTime(this.txt_pldate.Text.Trim());
            //执行添加
            bool pd = BLL.OrdersManage.AddAllOrders(or);
            if (pd)
            {
                this.lbl_plbcts.Text = "保存成功";
                rpt_ordersSX();
            }
            else
            {
                this.lbl_plbcts.Text = "保存失败";
            }
        }

        //修改信息框隐藏
        protected void Button2_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
        }

        //修改信息保存
        protected void btn_pl2bc_Click(object sender, EventArgs e)
        {
            //获取内容并保存至Orders中
            Orders or = new Orders();
            or.Or_Id = Convert.ToInt32(this.lbl_pl2orid.Text.Trim());
            or.Or_UsId = Convert.ToInt32(this.txt_pl2usid.Text.Trim());
            or.Or_GmId = Convert.ToInt32(this.txt_pl2gmid.Text.Trim());
            or.Or_Price = Convert.ToDouble(this.txt_pl2price.Text.Trim());
            or.Or_Goid = Convert.ToInt32(this.txt_pl2goid.Text.Trim());
            or.Or_Date = Convert.ToDateTime(this.txt_pl2date.Text.Trim());
            bool bl = BLL.OrdersManage.UpdaOrders(or);
            if (bl)
            {
                this.lbl_pl2bcts.Text = "保存成功";
                //刷新表信息
                rpt_ordersSX();
            }
            else
            {
                this.lbl_pl2bcts.Text = "保存失败";
            }
        }
        //游戏名称替换游戏id
        public string GmIdisName(string id)
        {
            List<Game> ls = BLL.GameManage.SeleIdGame(Convert.ToInt32(id));
            return ls[0].Gm_Name.ToString();
        }
        //用户名替换用户Id
        public string UsIdisName(string id)
        {
            List<Users> ls = BLL.UsersManage.SeleIdUsers(Convert.ToInt32(id));
            return ls[0].Us_Name.ToString();
        }

        //确定删除
        protected void btn_delequedin_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["deid"]);
            bool bl = BLL.OrdersManage.DeleOrders(id);
            if (bl)
            {
                //刷新表信息
                rpt_ordersSX();
                this.pl_delete.Visible = false;
            }
        }

        //取消删除
        protected void btn_delequxiao_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = false;
        }

        //刷新
        protected void imgbtnsx_Click(object sender, ImageClickEventArgs e)
        {
            //刷新表
            rpt_ordersSX();
        }

        //查询
        protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            //获取输入内容
            string name = this.txt_usid.Text.Trim();
            //判断是否输入
            if (name == "")
            {
                this.lbl_ChaXunTiShi.Text = "请输入查询内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            //查询
            List<Orders> ls = BLL.OrdersManage.SeleLikeUsNameOrders(name);
            if (ls.Count == 0)
            {
                this.lbl_ChaXunTiShi.Text = "未找到相关内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            this.lbl_ChaXunTiShi.Text = "";
            this.img_weizhaodao.Visible = false;
            this.rptorders.DataSource = ls;
            this.rptorders.DataBind();

        }

        
    }
}